<?php

session_start();

require_once($_SERVER['DOCUMENT_ROOT'].'/incofarming/Functions/config.php');
require_once($_SERVER['DOCUMENT_ROOT'].'/incofarming/Functions/class/user_model.php');

$user_model = new User_model();

$id_user = $_SESSION['id_user'];//echo $id_user;

$res = $user_model->get_koperasi_data_from_iduser($id_user);

while($row = mysql_fetch_array($res)){
	$kode_telp = $user_model->get_kota($row['IDKOTA']);
	$kode_telp = mysql_fetch_array($kode_telp);
	$prov =  $user_model->get_prov($kode_telp['IDPROPINSI']);
	$prov = mysql_fetch_array($prov);
	$kop_data = array(
		'id_kop' => $row['IDKOPERASI'],
		'nama_kop' => $row['NAMAKOPERASI'],
		'alamat_kop' => $row['ALAMAT'],
		'no_telp' => $row['NOTELP'],
		'no_fax' => $row['NOFAX'],
		'tgl_berdiri' => $row['TGLBERDIRI'],
		'email' => $row['EMAIL'],
		'info_kop' => $row['INFORMASI'],
		'foto' => $row['IDFOTO'],
		'kode_telp' => $kode_telp['KODETELP'],
		'kota' => $kode_telp['NAMAKOTA'],
		'provinsi' => $prov['NAMAPROPINSI']
	);
}

$res_user = $user_model->get_user_pass($id_user);
$user_arr = mysql_fetch_array($res_user);

if(isset($_POST['save'])){

	$nama = $_POST['nama-koperasi'];
	$alamat = $_POST['alamat-koperasi'];
	$no_telp = $_POST['no-kantor'];
	$no_fax = $_POST['no-fax'];
	$tgl = $_POST['tgl-berdiri'];
	$info = $_POST['info-koperasi'];
	
	$kop_arr = array(
		'NAMAKOPERASI' => $nama,
		'ALAMAT' => $alamat,
		'NOTELP' => $no_telp,
		'NOFAX' => $no_fax,
		'TGLBERDIRI' => $tgl,
		'INFORMASI' => $info
	);
	
	$user_arr = array(
		'IDUSER' => $id_user
	);
	
	$user_model->update_user($kop_arr, $user_arr, "koperasi");
	
	header('Location: /incofarming/Functions/koperasi/dashkop.php');
	
} else {

	include($_SERVER['DOCUMENT_ROOT'].'/incofarming/Views/koperasi/edit-user_view.php');

}



?>